package erfgame.core;

import java.util.Arrays;
import java.util.List;

public class AndFilter<K> implements Filter<K> {
	private List<Filter<K>> filters;
	
	public AndFilter( Filter<K>... filters ) {
		this( Arrays.asList( filters ) );
	}
	
	public AndFilter( List<Filter<K>> filters ) {
		this.filters = filters;
	}

	public boolean accept(K o) {
		boolean result = true;
		for( int i=0; i<filters.size(); i++ ) {
			Filter<K> filter = filters.get( i );
			if( !(result = filter.accept(o)) ) {
				break;
			}
		}
		return result;
	}
}
